home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / share / 11 / setup.exe / %MAINDIR% / DEMOS / CIFTP / FTPEXP / ftp.bas < prev    next >
Encoding:
BASIC Source File  |  2000-09-07  |  5.9 KB  |  176 lines

  1. Attribute VB_Name = "FTPSystem"
  2. '--------------------------------------------------------
  3. '<Purpose> provides support for a remote FTP system
  4. '--------------------------------------------------------
  5.  
  6. Option Explicit
  7.  
  8. '<Constant>----------------------------------------------
  9. Public Const ftpMaxSessions         As Integer = 10
  10. '</Constant>---------------------------------------------
  11.  
  12.  
  13. '------------------------------------------------------------
  14. '<Purpose> populates the TreeView with FTP Servers that
  15. ' are designated to be "reconnected at logon"
  16. '------------------------------------------------------------
  17. Public Sub AddFTPServers(ThisExplorer As Form, ParentNode As Node)
  18.     Dim DriveImage      As Integer
  19.     Dim InstanceServer  As FTPServer
  20.     Dim TheseNodes      As Nodes
  21.     Dim WorkingNode     As Node
  22.     Dim NodeKey         As String
  23.     Dim ParentKey       As String
  24.     
  25.     ThisExplorer.MousePointer = vbArrowHourglass
  26.     
  27.     '---- errors can be generated from duplicate keys; ignore
  28.     On Error Resume Next
  29.     
  30.     '---- cache nodes collection
  31.     Set TheseNodes = ThisExplorer.Tree.Nodes
  32.     
  33.     ParentKey = ParentNode.Key & "."
  34.     
  35.     For Each InstanceServer In MapServers.Servers
  36.         NodeKey = ParentKey & InstanceServer.Alias
  37.         
  38.         If (Not IsKeyed(TheseNodes, NodeKey)) Then
  39.             If (InstanceServer.Reconnect = vbChecked) Then
  40.                 '---- add the node to the tree
  41.                 Set WorkingNode = TheseNodes.Add(ParentNode, tvwChild, NodeKey, InstanceServer.Alias, imgFTPDrive)
  42.                 
  43.                 '---- also create and add attachment
  44.                 Dim ThisAttachment As New Attachment
  45.                 Dim ThisSession As New Session
  46.                 
  47.                 ThisAttachment.NodeType = nodFTPServer
  48.                 Set ThisSession.ThisServer = InstanceServer
  49.                 Set ThisAttachment.Session = ThisSession
  50.                 ThisAttachment.DrivePath = "/"
  51.                 Call ThisExplorer.Attachments.Add(ThisAttachment, NodeKey)
  52.                 
  53.                 Set ThisSession = Nothing
  54.                 Set ThisAttachment = Nothing
  55.                                 
  56.                 '---- add searching placeholder
  57.                 Call TheseNodes.Add(WorkingNode, tvwChild, WorkingNode.Key & nodPlaceHolder, nodPlaceHolder, imgPlaceHolder)
  58.             End If
  59.         End If
  60.     Next
  61.     
  62. Cleanup:
  63.     On Error GoTo 0
  64.     
  65.     Set InstanceServer = Nothing
  66.     Set TheseNodes = Nothing
  67.     Set WorkingNode = Nothing
  68.     
  69.     ThisExplorer.MousePointer = vbDefault
  70. End Sub
  71.  
  72. '--------------------------------------------------------
  73. '<Purpose> starts the process of getting FTP directories
  74. '--------------------------------------------------------
  75. Public Function ListFTPServer(ThisExplorer As Form, ServerNode As Node) As Boolean
  76.     Dim ThisSession     As Form
  77.     Dim ThisAttachment  As Attachment
  78.     
  79.     On Error GoTo BadSession
  80.     Set ThisAttachment = ThisExplorer.Attachments.Item(ServerNode.Key)
  81.     Set ThisSession = ThisAttachment.Session
  82.         
  83.     '---- create the session and set the callback
  84.     With ThisSession
  85.         Call .InitSession
  86.         .WorkingDir = ThisAttachment.DrivePath
  87.         Call .Connect
  88.         Set .ServerNode = ServerNode
  89.         Set .ThisExplorer = ThisExplorer
  90.         Set .ThisCallback = New FTPCallback
  91.     End With
  92.     
  93.     ListFTPServer = True
  94.         
  95. Cleanup:
  96.     On Error GoTo 0
  97.     Set ThisSession = Nothing
  98.     Set ThisAttachment = Nothing
  99.     Exit Function
  100.     
  101. BadSession:
  102.     ListFTPServer = False
  103.     GoTo Cleanup
  104. End Function
  105.  
  106. Public Function ChangeFTPDir(Session As Form, DirName As String) As Boolean
  107.   
  108.     Session.MousePointer = vbArrowHourglass
  109.     
  110.     '---- a directory selection has been made
  111.     '---- now update the listboxes
  112.     If (DirName = "..") Then
  113.         Session.ciSession.WorkingDirectory = ".."
  114.         Session.ciSession.CWD
  115.     ElseIf (DirName = ".") Then
  116.         Session.ciSession.WorkingDirectory = "/"
  117.         Session.ciSession.CWD
  118.     Else
  119.         Session.ciSession.WorkingDirectory = DirName
  120.         Session.ciSession.CWD
  121.     End If
  122.     
  123.     Session.ciSession.PWD
  124.     Session.ciSession.PASV
  125.     
  126. End Function
  127.  
  128. '--------------------------------------------------------
  129. '<Purpose> maps an FTPServer to the Explorer
  130. '--------------------------------------------------------
  131. Public Function MapServer(ThisExplorer As Form) As Boolean
  132.     Dim ParentNode      As Node
  133.     Dim ServerNode      As Node
  134.     Dim TheseNodes      As Nodes
  135.     Dim ThisSession     As New Session
  136.     Dim ServerKey       As String
  137.     
  138.     With MapServers
  139.         Set .ThisExplorer = ThisExplorer
  140.         .Show vbModal
  141.         If (Not .PressedOK) Then GoTo Cleanup
  142.     End With
  143.     
  144.     '---- cache nodes collection
  145.     Set TheseNodes = ThisExplorer.Tree.Nodes
  146.     
  147.     Set ThisSession.ThisServer = MapServers.ThisServer
  148.  
  149.     '---- add the node to the tree
  150.     Set ParentNode = TheseNodes.Item("Root.FTPServers")
  151.     ServerKey = ParentNode.Key & "." & ThisSession.ThisServer.Alias
  152.     
  153.     '---- may already be in TreeView, if not add it
  154.     If (Not IsKeyed(TheseNodes, ServerKey)) Then
  155.         Set ServerNode = TheseNodes.Add(ParentNode, tvwChild, ServerKey, ThisSession.ThisServer.Alias, imgFTPDrive)
  156.     
  157.         '---- add searching placeholder
  158.         Call TheseNodes.Add(ServerNode, tvwChild, ServerNode.Key & nodPlaceHolder, nodPlaceHolder, imgPlaceHolder)
  159.         
  160.         '---- also create and add attachment
  161.         Dim ThisAttachment As New Attachment
  162.         ThisAttachment.NodeType = nodFTPServer
  163.         Set ThisAttachment.Session = ThisSession
  164.         Call ThisExplorer.Attachments.Add(ThisAttachment, ServerKey)
  165.         Set ThisAttachment = Nothing
  166.     
  167.     End If
  168.  
  169. Cleanup:
  170.     Set ParentNode = Nothing
  171.     Set TheseNodes = Nothing
  172.     Set ThisSession = Nothing
  173.     Set ServerNode = Nothing
  174.     
  175. End Function
  176.